<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>添加题库</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加学生</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="" style="width: 90%">


    <input type="hidden" id="uid" name="uid" value="<{$user.uid}>">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入姓名" class="layui-input" value="<{$user.name}>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="mobile" lay-verify="mobile" autocomplete="off" placeholder="输入手机号" class="layui-input" value="<{$user.mobile}>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">班级</label>
        <div class="layui-input-block">
            <select name="grade" lay-verify="grade" lay-search>
                <foreach name="grade" item="vo" >
                    <option <if condition="$vo.id eq $user['grade']">selected</if> value="<{$vo.id}>"><{$vo.name}></option>

                </foreach>

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地区</label>
        <div class="layui-input-inline">
            <select name="province" id="province" lay-verify="province" lay-filter="province" lay-search>
                <option value=""></option>
                <foreach name="region_ret.1" item="vo" >
                    <option <if condition="$vo.REGION_ID eq $student_region[1]['REGION_ID']">selected</if> value="<{$vo.REGION_ID}>"><{$vo.REGION_NAME}></option>
                </foreach>
            </select>
            <select name="city" id="city" lay-verify="city" lay-filter="city" lay-search>
                <option value=""></option>
                <foreach name="region_ret.2" item="vo" >
                    <option <if condition="$vo.REGION_ID eq $student_region[2]['REGION_ID']">selected</if> value="<{$vo.REGION_ID}>"><{$vo.REGION_NAME}></option>
                </foreach>
            </select>
            <select name="district" id="district" lay-verify="district" lay-filter="district" lay-search>
                <option value=""></option>
                <foreach name="region_ret.3" item="vo" >
                    <option <if condition="$vo.REGION_ID eq $student_region[3]['REGION_ID']">selected</if> value="<{$vo.REGION_ID}>"><{$vo.REGION_NAME}></option>
                </foreach>
            </select>
            <input type="text" name="address" lay-verify="address" autocomplete="off" placeholder="请输入地区" class="layui-input" value="<{$user.district}>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学校</label>
        <div class="layui-input-block">
            <input type="text" name="school" lay-verify="school" autocomplete="off" placeholder="请输入学校" class="layui-input" value="<{$user.school}>">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="不输入,则不修改" class="layui-input" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="__PUBLIC__/BeginnerAdmin/plugins/layui/layui.js"></script>
<script type="text/javascript" src="__PUBLIC__/AmazeUI/assets/js/jquery-1.8.0.min.js"></script>
<script>
    function settime() {
        // window.location.href = 'Admin_Topic_NewTopicUI.html?examinationid=<{$examinationid}>';
        var index=parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    layui.use(['form', 'laydate'], function() {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            name: function(value) {
                if(value.length < 2) {
                    return '姓名至少2个字符';
                }
            },
            mobile: function(value) {
                if(value.length != 11) {
                    return '手机号为11个字符';
                }
            },
            grade: function(value) {
                if(value.length == '') {
                    return '班级不为空';
                }
            },
            district:function (value) {
                if(value.length == '') {
                    return '地区必填';
                }
            },
            school:function (value) {
                if(value.length == '') {
                    return '学校必填';
                }
            }

        });

        //监听提交
        form.on('submit(demo1)', function(data) {

            $.post('Admin_Student_EditStudent.html',data.field,function (ret) {
                if(ret.code == 200){
                    layer.msg('修改成功');
                    setTimeout('settime()', 1000);//延时执行，让人看得更清楚
                }else{
                    layer.alert(ret.msg);
                }
            },'json');
            return false;
        });
        

        form.on('select(province)', function(data){
            $("#city").html('<option value="">请选择市</option>');
            $("#district").html('<option value="">请选择区</option>');

            if (data.value == 0){
                return false;
                form.render('select');
            }
            $.post('Admin_Student_Region.html',{regionid:data.value},function (ret) {
                if(ret.code == 200){
                    var city_data = '<option value=""></option>';
                    for (var city_i = 0 in ret.data){
                        city_data += '<option value="'+ret.data[city_i].REGION_ID+'">'+ret.data[city_i].REGION_NAME+'</option>';
                    }
                    $("#city").html(city_data);
                    form.render('select');
                }else{
                    layer.alert(ret.msg);
                }
            },'json');
        });
        form.on('select(city)', function(data){
            $("#district").html('<option value="">请选择区</option>');
            if (data.value == 0){
                return false;
                form.render('select');
            }

            $.post('Admin_Student_Region.html',{regionid:data.value},function (ret) {
                if(ret.code == 200){
                    var district_data = '<option value=""></option>';
                    for (var district_i = 0 in ret.data){
                        district_data += '<option value="'+ret.data[district_i].REGION_ID+'">'+ret.data[district_i].REGION_NAME+'</option>';
                    }
                    $("#district").html(district_data);
                    form.render('select');
                }else{
                    layer.alert(ret.msg);
                }
            },'json');
        });
    });
</script>
</body>
</html>